using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Library;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library;
using NCS.Module.CMS.Library.Definitions;
using NCS.Module.CMS.Library.Distributions;

namespace NCS.Module.CMS.Web.Sport
{
    public partial class LeftPosition1 : CMSWebControl
    {
        //public int zoneid;
        protected int divid = 1;
        protected void Page_Load(object sender, EventArgs e)
        {
            //zoneid = ConvertUtility.ToInt32(Portal[Constants.CMS_SP_TinNong + AppEnv.GetLanguage()]);
            //DataTable other = DistributionController.GetDistributedContents(zoneid, 5, (int)CMSDistributionRank.Special);

            DataTable other = DistributionController.GetDistributedHotNewsContentsbyPortal(ConvertUtility.ToInt32(AppEnv.PortalId()), 5);
            
            if (other.Rows.Count > 0)
            {
                rptContent.DataSource = other;
                rptContent.DataBind();
            }

        }

        protected void rptContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView currow = (DataRowView)e.Item.DataItem;
                HyperLink hplTitle = (HyperLink)e.Item.FindControl("hplTitle");
                hplTitle.Text = ConvertUtility.ToString(currow["Content_Headline"]);
                hplTitle.NavigateUrl = BuildUrlByDistId((int)currow["Distribution_ID"], (int)currow["Distribution_ZoneID"]);

                Label lblDate = (Label)e.Item.FindControl("lblDate");
                lblDate.Text = ConvertUtility.FormatTimeVn(ConvertUtility.ToDateTime(currow["Distribution_CreateDate"]));

                Image imgAvatar = (Image)e.Item.FindControl("imgAvatar");
                if (ConvertUtility.ToString(currow["SpecialAvatar"]) != string.Empty)
                {
                    imgAvatar.ImageUrl = MultimediaUtility.GetSpecialAvatar(currow["SpecialAvatar"].ToString());
                    imgAvatar.Attributes.Add("onclick", "javascript:window.location='" + BuildUrlByDistId((int)currow["Distribution_ID"], (int)currow["Distribution_ZoneID"]) + "'");
                    imgAvatar.Attributes.Add("style", "cursor:hand");
                    imgAvatar.AlternateText = MiscUtility.SafeHtmlToText(ConvertUtility.ToStringWithoutFontBold(currow["Content_AvatarDescription"]));
                }
                else
                {
                    imgAvatar.Visible = false;
                }

                Literal lblSummary = (Literal)e.Item.FindControl("lblSummary");
                lblSummary.Text = ConvertUtility.ToStringWithoutFontBold(currow["Content_Teaser"], 250).TrimEnd();

                HyperLink hpldetail = (HyperLink)e.Item.FindControl("hpldetail");
                hpldetail.NavigateUrl = BuildUrlByDistId((int)currow["Distribution_ID"], (int)currow["Distribution_ZoneID"]);
            }
        }
    }
}